package com.bolt.report.engine;

import com.bolt.common.utils.StrUtil;
import com.bolt.report.definition.ReportDefinition;
import com.bolt.report.exception.ReportException;

import java.util.concurrent.ConcurrentHashMap;

public abstract class AbstractReportManager implements ReportDefManager  {

    //protected final static Logger logger = LoggerFactory.getLogger(AbstractReportManager.class);

    protected ConcurrentHashMap<String, ReportDefinition> definitionLookup = new ConcurrentHashMap<>();


    public ReportDefinition loadReportDefinition(String report) {
        if (StrUtil.isEmpty(report)) {
            throw new ReportException("report bean class is null");
        }
        ReportDefinition reportDefinition = definitionLookup.get(report);
        if (reportDefinition == null) {
            reportDefinition = parseReportDefinition(report);
            if (reportDefinition == null) {
                throw new ReportException("cannot load report name:[".concat(report).concat(" ]error!"));
            }
        }
        return reportDefinition;
    }



}